<?php

//error_reporting(E_ERROR | E_WARNING | E_PARSE);
mysql_connect(localhost, root, root);
@mysql_select_db(miniflyer) or die("Unable to select database");
set_time_limit(0);
ini_set("memory_limit", "200M");
//$dateTime = date("Y-m-d",strtotime("-1 day"));
//$handle = fopen("http://192.168.0.185/log/test/$dateTime.'a'", "r");
$handle = fopen("/var/www/log/miniflyer/log", "r");
while (!feof($handle)) {
    $buffer = fgets($handle, 10960);
    // $array[] = $buffer;
    $arr = json_decode($buffer, true);
    $id100 = $arr["data"];
    $arr2 = json_decode($id100, true);
    $id = $arr2["UIEnterInfo"];
    $arr3 = json_decode($id, true);
    //buyAvatar
    $id101 = $arr2["buyAvatar"];
    $arr4 = json_decode($id101, true);
    //dayEffort
    $id102 = $arr2["dayEffort"];
    $arr5 = json_decode($id102, true);
    //dayGetMoneyFromIAP
    $id103 = $arr2["dayGetMoneyFromIAP"];
    $arr6 = json_decode($id103, true);
    //equipUpInfos
    $id104 = $arr2["equipUpInfos"];
    $arr7 = json_decode($id104, true);
    //equipUsedInfos
    $id105 = $arr2["equipUsedInfos"];
    $arr8 = json_decode($id105, true);

    $id2 = $arr3["1"];
    $id3 = $arr3["2"];
    $id4 = $arr3["3"];
    $id5 = $arr3["4"];
    $id6 = $arr3["5"];
    $id7 = $arr3["6"];
    $id8 = $arr3["7"];
    $id9 = $arr3["8"];
    $id10 = $arr3["9"];
    $id11 = $arr3["10"];
    $id12 = $arr3["11"];
    $id13 = $arr3["12"];


    $id14 = $arr4["C1"];
    $id15 = $arr4["C2"];
    $id16 = $arr4["C3"];
    $id17 = $arr4["C4"];
    $id18 = $arr4["C5"];
    $id19 = $arr4["C6"];

    $id20 = $arr5["A"];
    $id21 = $arr5["B"];
    $id22 = $arr5["C"];

    $id23 = $arr2["dayGetMoney"];
    $id24 = $arr6["099IAP"];
    $id25 = $arr6["099Time"];
    $id26 = $arr6["099Total"];
    $id27 = $arr6["1999IAP"];
    $id28 = $arr6["1999Time"];
    $id29 = $arr6["1999Total"];
    $id30 = $arr6["199IAP"];
    $id31 = $arr6["199Time"];
    $id32 = $arr6["199Total"];
    $id33 = $arr6["299IAP"];
    $id34 = $arr6["299Time"];
    $id35 = $arr6["299Total"];
    $id36 = $arr6["499IAP"];
    $id37 = $arr6["499Time"];
    $id38 = $arr6["499Total"];
    $id39 = $arr6["999IAP"];
    $id40 = $arr6["999Time"];
    $id41 = $arr6["999Total"];

    $id42 = $arr2["dayPlayAvgTime"];
    $id43 = $arr2["dayPlayLongTime"];
    $id44 = $arr2["dayPlayNowTime"];
    $id45 = $arr2["dayPlayShortTime"];
    $id46 = $arr2["dayPlayTime"];
    $id47 = $arr2["dayTotalTime"];
    $id48 = $arr2["dayUsedMoney"];

    $id49 = $arr7["B1"];
    $id50 = $arr7["B2"];
    $id51 = $arr7["B3"];
    $id52 = $arr7["B4"];
    $id53 = $arr7["B5"];
    $id54 = $arr7["B6"];
    $id55 = $arr7["B7"];

    $id56 = $arr8["A1"];
    $id57 = $arr8["A2"];
    $id58 = $arr8["A3"];
    $id59 = $arr8["A4"];  
    $id60 = $arr8["A5"];

    $id61 = $arr2["firstlogindata"];
    $id62 = $arr2["jailbreak"];
    $id63 = $arr2["lastUi"]; 
    $id64 = $arr2["nowMoney"];
    $id65 = $arr2["totalMoney"];
    $id66 = $arr2["totalTime"];
    $id67 = $arr["deviceid"];
    $id68 = $arr["gamename"];
    $id101 = $arr["createdate"];
    $id102 = $arr2["DataTime"];
    $id103 = $arr2["CoinDoubleIAP"];

    $s = 0;
    foreach ((array) $arr as $item => $value) {   //Warning: Invalid argument supplied for foreach
        $s = count($value); //
    }
    for ($i = 0; $i < $s; $i++) {
    	
        $SceneMainMenu = $id2;
        $SceneMainGame = $id3;
        $SceneStash = $id4;
        $SceneOption = $id5;
        $SceneCredits = $id6;
        $SceneGameOver = $id7;
        $SceneAvatar = $id8;
        $SceneUpgrades = $id9;
        $SceneItems = $id10;
        $SceneBank = $id11;
        $SceneExcess = $id12;
        $SceneProfile = $id13;

        $buyAvatarC1 = $id14;
        $buyAvatarC2 = $id15;
        $buyAvatarC3 = $id16;
        $buyAvatarC4 = $id17;
        $buyAvatarC5 = $id18;
        $buyAvatarC6 = $id19;

        $dayEffortA = $id20;
        $dayEffortB = $id21;
        $dayEffortC = $id22;

        $dayGetMoney = $id23;

        $_099IAP = $id24;
        $_099Time = $id25;
        $_099Total = $id26 ;
        $_1999IAP = $id27;
        $_1999Time = $id28;
        $_1999Total = $id29;
        $_199IAP = $id30 ;
        $_199Time = $id31;
        $_199Total =  $id32 ;
        $_299IAP = $id33;
        $_299Time = $id34;
        $_299Total = $id35; 
        $_499IAP = $id36 ;
        $_499Time = $id37;
        $_499Total = $id38 ;
        $_999IAP = $id39;
        $_999Time = $id40;
        $_999Total = $id41;

        $dayPlayAvgTime =  $id42;
        $dayPlayLongTime =  $id43; 
        $dayPlayNowTime = $id44;
        $dayPlayShortTime =  $id45;
        $dayPlayTime = $id46;
        $dayTotalTime = $id47;
        $dayUsedMoney = $id48;

        $equipUpInfosB1 = $id49;
        $equipUpInfosB2 = $id50;
        $equipUpInfosB3 = $id51;
        $equipUpInfosB4 = $id52;
        $equipUpInfosB5 =  $id53 ;
        $equipUpInfosB6 =  $id54;
        $equipUpInfosB7 =  $id55 ;

        $equipUsedInfosA1 = $id56;
        $equipUsedInfosA2 = $id57;
        $equipUsedInfosA3 = $id58 ;
        $equipUsedInfosA4 = $id59 ; 
        $equipUsedInfosA5 = $id60 ;

        $firstlogindata =  $id61;
        $jailbreak = $id62;
        $lastUi =  $id63;
        $nowMoney =  $id64 ;
        $totalMoney = $id65;
        $totalTime = $id66 ;
        $deviceid = $id67;
        $gamename = $id68 ;
        $createdate = $id101;
        //DataTime
        $dataTime = $id102;
        $coinDoubleIAP = $id103;
             

   

        mysql_query("INSERT INTO miniflyer_query (  SceneMainMenu,
        SceneMainGame,
        SceneStash,
        SceneOption,
        SceneCredits,
        SceneGameOver,
        SceneAvatar,
        SceneUpgrades,
        SceneItems,
        SceneBank,
        SceneExcess,
        SceneProfile,

        buyAvatarC1,
        buyAvatarC2,
        buyAvatarC3,
        buyAvatarC4,
        buyAvatarC5,
        buyAvatarC6,

        dayEffortA,
        dayEffortB,
        dayEffortC,

        dayGetMoney,

        _099Time,
        _099Total,
        _1999Time,
        _1999Total,
        _199Time,
        _199Total,
        _299Time,
        _299Total,
        _499Time,
        _499Total,
        _999Time,
        _999Total,

        dayPlayAvgTime,
        dayPlayLongTime,
        dayPlayNowTime,
        dayPlayShortTime,
        dayPlayTime,
        dayTotalTime,
        dayUsedMoney,

        equipUpInfosB1,
        equipUpInfosB2,
        equipUpInfosB3,
        equipUpInfosB4,
        equipUpInfosB5,
        equipUpInfosB6,
        equipUpInfosB7,

        equipUsedInfosA1,
        equipUsedInfosA2,
        equipUsedInfosA3,
        equipUsedInfosA4,
        equipUsedInfosA5,

        firstlogindata,
        jailbreak,
        lastUi,
        nowMoney,
        totalMoney,
        totalTime,
        deviceid,
        gamename,
        createdate,
        date,
        firstlogin,
        dataTime,
        coinDoubleIAP) 
                    VALUES('$SceneMainMenu',
        '$SceneMainGame',
        '$SceneStash',
        '$SceneOption',
        '$SceneCredits',
        '$SceneGameOver',
        '$SceneAvatar',
        '$SceneUpgrades',
        '$SceneItems',
        '$SceneBank',
        '$SceneExcess',
        '$SceneProfile',
        '$buyAvatarC1',
        '$buyAvatarC2',
        '$buyAvatarC3',
        '$buyAvatarC4',
        '$buyAvatarC5',
        '$buyAvatarC6',
        '$dayEffortA',
        '$dayEffortB',
        '$dayEffortC',
        '$dayGetMoney',
        '$_099Time',
        '$_099Total',
        '$_1999Time',
        '$_1999Total',
        '$_199Time',
        '$_199Total',
        '$_299Time',
        '$_299Total',
        '$_499Time',
        '$_499Total',
        '$_999Time',
        '$_999Total',
        '$dayPlayAvgTime',
        '$dayPlayLongTime',
        '$dayPlayNowTime',
        '$dayPlayShortTime',
        '$dayPlayTime',
        '$dayTotalTime',
        '$dayUsedMoney',
        '$equipUpInfosB1',
        '$equipUpInfosB2',
        '$equipUpInfosB3',
        '$equipUpInfosB4',
        '$equipUpInfosB5',
        '$equipUpInfosB6',
        '$equipUpInfosB7',
        '$equipUsedInfosA1',
        '$equipUsedInfosA2',
        '$equipUsedInfosA3',
        '$equipUsedInfosA4',
        '$equipUsedInfosA5',
        '$firstlogindata',
        '$jailbreak',
        '$lastUi',
        '$nowMoney',
        '$totalMoney',
        '$totalTime',
        '$deviceid',
        '$gamename',
        '$createdate',
        '$createdate','$firstlogindata','$dataTime','$coinDoubleIAP')") or die(mysql_error());
    }
}
fclose($handle);
//fclose($fp);
print "Import successful!<br>";

?>
